//
//  ChannelCell.m
//  Fireball
//
//  Created by 任长平 on 2017/12/4.
//  Copyright © 2017年 任长平. All rights reserved.
//

#import "ChannelCell.h"

@interface ChannelCell ()
///标题
@property (nonatomic, strong) UILabel *title ;
@end

@implementation ChannelCell
-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.clipsToBounds = YES;
        self.layer.cornerRadius = 2.0;

        
        self.title = [[UILabel alloc]init];
        [self.contentView addSubview:_title];
        self.title.backgroundColor = [UIColor xm_colorFromRGB:0xFFFFFF];
        self.title.layer.masksToBounds = YES;
        self.title.layer.cornerRadius = 2.0;
        self.title.font = [UIFont xm_font:15.0];
        self.title.textAlignment = NSTextAlignmentCenter;
        self.title.textColor = [UIColor xm_colorFromRGB:0x5D646E];
        
        self.delBtn = [[UIButton alloc]init];
        [self.contentView addSubview:_delBtn];
        [self.delBtn setImage:[UIImage imageNamed:@"image_delete"] forState:UIControlStateNormal];
        [self.delBtn addTarget:self action:@selector(deleteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        self.title.text = @"关注";
        
    }
    return self;
}

-(void)setMenu:(AticleMenu *)menu{
    _menu = menu;
    self.title.text = _menu.Text;
    if (_menu.editable) {
        if (self.editing) {
            self.delBtn.hidden = !_menu.selected;
        }else{
            self.delBtn.hidden = YES;
        }
    }else{
        self.delBtn.hidden = YES;
    }

}
-(void)setEditing:(BOOL)editing{
    _editing = editing;
}


-(void)deleteButtonClick:(UIButton *)sender{
    if (self.deleteBlock) {
        self.deleteBlock(sender);
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.title.frame = CGRectMake(5, 5, self.width-10, self.height-10);
    self.delBtn.frame = CGRectMake(self.width - 18, 0, 18, 18);

}

@end
